﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace WebApp
{
    public partial class IN : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

      
        protected void Timer1_Tick(object sender, EventArgs e)
        {
            this.Label1.Text = System.DateTime.Now.ToString();
        }        
      
        protected void btnIn_Click(object sender, EventArgs e)
        {
            try
            {

                string strCn = "server=pc.hstc.cn;database=dhd2014112138;uid=2014112138;pwd=19960516";
                SqlConnection conn = new SqlConnection(strCn);
                conn.Open();

                StringBuilder sb = new StringBuilder(1024);
                sb.Append("INSERT INTO UserInfo ");
                sb.Append("                (UserName, Password) ");
                sb.Append("VALUES   (@UserName,@Password) ");
                SqlParameter[] pms = new SqlParameter[2];
                pms[0] = new SqlParameter("@UserName", this.txtNa.Text);
                pms[1] = new SqlParameter("@Password", this.txtPwd1.Text);

                //StringBuilder sbr = new StringBuilder(1024);
                //sb.Append("INSERT INTO StudentInfo ");
                //sb.Append("                (StudNo, Name, Gender,Class, College, Memo) ");
                //sb.Append("VALUES   (@StudNo,@Name,@Gender,@Class,@College,@Memo) ");
                //SqlParameter[] pms1 = new SqlParameter[6];
                //pms1[0] = new SqlParameter("@StudNo", this.txtNo.Text);
                //pms1[1] = new SqlParameter("@Name", this.txtName.Text);
                //pms1[2] = new SqlParameter("@Gender", this.txtSex.Text);
                //pms1[3] = new SqlParameter("@Class", this.txtCla.Text);
                //pms1[4] = new SqlParameter("@College", this.txtColl.Text);
                //pms1[5] = new SqlParameter("@Memo", this.txtMe.Text);
                int intResult = SqlHelper.ExecuteNonQuery(sb.ToString(), pms);
                //int intResult1 = SqlHelper.ExecuteNonQuery(sb.ToString(), pms1);
                if (intResult > 0)
                {
                    //if (intResult1 > 0)
                        ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('注册成功！请返回登录页面进行登录！')", true);
                }
            }
            catch (Exception ex)
            {
                this.lblInfo.Text = "注册失败！用户已存在，请重新注册……具体原因：" + ex.Message;
            }
        }

        protected void btnNew_Click(object sender, EventArgs e)
        {
            this.txtNa.Text = "";
            this.txtPwd1.Text = "";
            this.txtPwd2.Text = "";
            //this.txtNo.Text = "";
            //this.txtName.Text = "";
            //this.txtSex.Text = "";
            //this.txtCla.Text = "";
            //this.txtColl.Text = "";
            //this.txtMe.Text = "";
        }

      
    }
}